package dataInterpreter;

public class Feature3 extends Feature {
	public Feature3()
	{
		setType(3);
		setMinHeight(1);
		setMinWidth(3);
	}

	@Override
	public double calculateValue(double[][] image, int x, int y, int width, int height) {
		double result = 0;
		double A1, B1, C1, D1, A2, B2, C2, D2, A3, B3, C3, D3;
		if (y == 0) {
			A1 = C1 = A2 = C2 = A3 = C3 = 0;
			if (x == 0)
				B1 = 0;
			else {
				B1 = image[x - 1][y - 1 + height];
			}
		} else if (x == 0) {
			A1 = B1 = 0;
			C1 = image[x - 1 + (width / 3)][y - 1];
			A2 = image[x - 1 + (width / 3)][y - 1];
			C2 = image[x - 1 + (2 * width / 3)][y - 1];
			A3 = image[x - 1 + (2 * width / 3)][y - 1];
			C3 = image[x - 1 + width][y - 1];
		} else {

			A1 = image[x - 1][y - 1];
			B1 = image[x - 1][y - 1 + height];
			C1 = image[x - 1 + (width / 3)][y - 1];
			A2 = image[x - 1 + (width / 3)][y - 1];
			C2 = image[x - 1 + (2 * width / 3)][y - 1];
			A3 = image[x - 1 + (2 * width / 3)][y - 1];
			C3 = image[x - 1 + width][y - 1];
		}
		B2 = image[x - 1 + (width / 3)][y - 1 + height];
		B3 = image[x - 1 + (2 * width / 3)][y - 1 + height];
		D1 = image[x - 1 + (width / 3)][y - 1 + height];
		D2 = image[x - 1 + (2 * width / 3)][y - 1 + height];
		D3 = image[x - 1 + width][y - 1 + height];

		double brancoE = A1 + D1 - (B1 + C1);
		double preto = A2 + D2 - (B2 + C2);
		double brancoD = A3 + D3 - (B3 + C3);
		result = preto - (brancoE + brancoD);
		setValue(result);
		return result;
	}
}
